using OhioState.Graphics.Proxy;
using OhioState.Math;

namespace OhioState.Graphics.OpenGL
{
    public class ClipPlaneHandler : OpenGLObject
    {
        private ClipPlaneProxy _clipProxy;
        private ClipPlaneGL _realClip;

        public ClipPlaneHandler(ClipPlaneProxy proxyObj) : base(proxyObj)
        {
            _clipProxy = proxyObj;
            _realClip = new ClipPlaneGL();
        }
        public void Enable(int plane)
        {
            if (this.Invalid)
            {
                double scale = 1.0;
                if (_clipProxy.IsAbove) scale = -1.0;
                _realClip.Clip[0] = scale * _clipProxy.ClipPlane.Normal[0];
                _realClip.Clip[1] = scale * _clipProxy.ClipPlane.Normal[1];
                _realClip.Clip[2] = scale * _clipProxy.ClipPlane.Normal[2];
                _realClip.Clip[3] = -(_realClip.Clip[0] * _clipProxy.ClipPlane.Point[0] + _realClip.Clip[1] * _clipProxy.ClipPlane.Point[1] + _realClip.Clip[2] * _clipProxy.ClipPlane.Point[2]);
            }
            _realClip.Enable(plane);


        }
        public void Disable(int plane)
        {
            _realClip.Disable(plane);
        }
    }
}
